package org.example.web.interceptor;

import org.example.model.User;
import org.example.web.utils.WebUtils;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class WebHandlerInterceptor implements HandlerInterceptor {

    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("WebHandlerInterceptor->preHandle()");
        return true;
    }

    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        System.out.println("WebHandlerInterceptor->postHandle()");
        modelAndView.addObject("session_info", WebUtils.get_session_info(request));
        modelAndView.addObject("session_user_info", WebUtils.get_session_user_info(request));
    }

    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        System.out.println("WebHandlerInterceptor->afterCompletion()");
    }
    
}
